// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import audioManager from "./AudioManager";

const {ccclass, property} = cc._decorator;

@ccclass
export default class Toast extends cc.Component {
    static height = 250

    @property({
        type: cc.Label,
        displayName: '弹框内容组件'
    })
    content: cc.Label

    @property({
        type: cc.Node,
        displayName: '关闭按钮'
    })
    close: cc.Node;


    protected audioManager

    start() {
        this.audioManager = audioManager
        this.close.on(cc.Node.EventType.TOUCH_START, this.onClose, this)
    }

    init(data: any = {}) {
        this.node.height = data.height || Toast.height;
        this.content.string = data.content;
        return this;
    }

    onClose(isClose = true) {
        this.node.active = !isClose
        this.audioManager.playBtnClickAudio()
    }

    // update (dt) {}
}
